/******************************************************************************
 * Copyright (C) 2017 Chengdu Dlhd information industry co. LTD.
 * All Rights Reserved.
 * 本软件为成都顶联互动信息产业有限公司开发研制。未经本公司正式书面同意，其他任何个人、团体不得使用、复制、修改或发布本软件.
 *****************************************************************************/
package net.dgg.dggcloud.service.jrcrm.common.tag;


import net.dgg.dggcloud.core.constants.Constants;
import net.dgg.dggcloud.service.common.base.SessionManager;
import net.dgg.dggcloud.service.entity.OperationRight;
import net.dgg.dggcloud.service.entity.Role;
import net.dgg.dggcloud.service.entity.user.User;
import net.dgg.dggcloud.service.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import java.util.List;

/**
 * @ClassName 〈SystemRightTag>
 * @Description
 * @Author 朱永波
 * @Date 2017/11/10 9:18
 */
public class SystemRoleTag extends TagSupport {
    /**
     * 权限的code
     */
    private String code;
    @Override
    public int doStartTag() throws JspException {
        try {
            Object roles = pageContext.getSession().getAttribute(Constants.USER_ROLES_SESSION_KEY);
            if(null != roles){
                List roleList = (List) roles;
                for(Object obj : roleList){
                    Role role = (Role) obj;
                    if(code.toLowerCase().equals(role.getRoleKey().toLowerCase())){
                        return 1;
                    }
                }
            }
            return super.doStartTag();
        } catch (Exception e) {
            throw new JspException(e);
        }
    }

    public void setCode(String code) {
        this.code = code;
    }
}
